using JNPF.Basics.Models;
using JNPF.Data;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JNPF.Basics.Logic
{
    /// <summary>
    /// 数据权限方案
    /// 版 本：V2.6.200509
    /// 版 权：引迈信息技术有限公司（https://www.yinmaisoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2018-11-08 
    /// </summary>
    internal class ModuleDataAuthorizeSchemeService : DataFactory, ModuleDataAuthorizeSchemeIService
    {
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<ModuleDataAuthorizeSchemeEntity>> GetList()
        {
            using (var db = this.Basic)
            {
                return await db.GetIQueryable<ModuleDataAuthorizeSchemeEntity>().OrderBy(o => o.SortCode).ToListAsync();
            }
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="moduleId">功能主键</param>
        /// <returns></returns>
        public async Task<List<ModuleDataAuthorizeSchemeEntity>> GetList(string moduleId)
        {
            using (var db = this.Basic)
            {
                return await db.GetIQueryable<ModuleDataAuthorizeSchemeEntity>().Where(m => m.ModuleId == moduleId).OrderBy(o => o.SortCode).ToListAsync();
            }
        }
        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        public async Task<ModuleDataAuthorizeSchemeEntity> GetInfo(string id)
        {
            using (var db = this.Basic)
            {
                return await db.GetEntityAsync<ModuleDataAuthorizeSchemeEntity>(m => m.Id == id);
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public async Task<int> Delete(ModuleDataAuthorizeSchemeEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.DeleteAsync(entity);
            }
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public async Task<int> Create(ModuleDataAuthorizeSchemeEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.InsertAsync(entity);
            }
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public async Task<int> Update(ModuleDataAuthorizeSchemeEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.UpdateAsync(entity);
            }
        }

    }
}
